<?php
/**
* Save the changes to a given transaction
*
* @author       Fabrice Douteaud <clearbudget@douteaud.com>
* @package      actions
* @access       public
*/

/***********************************************************************

  Copyright (C) 2008  Fabrice douteaud (clearbudget@douteaud.com)

    This file is part of ClearBudget.

    ClearBudget is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ClearBudget is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ClearBudget.  If not, see <http://www.gnu.org/licenses/>.


************************************************************************/
$db = class_db::getInstance();
// JSON flag to true as this always returns JSON data
self::$json = true;
// get the input fields
isset($_REQUEST['id'])?$id = $_REQUEST['id']:$id = null;
isset($_REQUEST['category'])?$category = $_REQUEST['category']:$category = null;
isset($_REQUEST['comment'])?$comment = $_REQUEST['comment']:$comment = null;
// preset the return message to its defaults
$returnMsg = $keys->error_UnknownError;
  
if($category == null || $category == '' || $category == 0) {
  $returnMsg = $keys->error_CategoryIsMandatory;
  return;
  }
  
// update the record if necessary (we have an ID, a Category and a Comment)
if($id != null) {
  $db->addFields('category', $category);
  $db->addFields('comments', $comment);
  $db->addWhere('id', '=', $id);
  $db->update('t_items');
  $returnMsg = $keys->success;
  }
?>